<template>
  <div class="dashboard-container">
    <!-- <div class="dashboard-text">姓名: {{ nickName }}</div> -->
    <!-- 使用svg-icon组件 -->
    <!-- 设置iconClass属性='文件名(没有后缀)' -->
    <!-- <svg-icon icon-class="dashboard" />
    <svg-icon icon-class="example" />
    <svg-icon icon-class="eye-open" /> -->
    <!-- <svg-icon icon-class="dashboard" /> -->
    <div class="process-template-list">
      <!-- 遍历每个假勤类型 -->
      <el-card v-for="category in processCategories" :key="category.id" class="box-card">
        <div slot="header" class="clearfix">
          <span>{{ category.typeName }}</span>
        </div>
        <!-- 展示该类别下的所有模板 -->
        <el-row :gutter="50">
          <el-col
            v-for="template in category.oaProcessTemplates"
            :key="template.id"
            :span="3"
            @click.native="gotoProcessDefinitionDetails(template.processDefinitionKey)"
          >
            <el-card class="hoverable-card">
              <img :src="template.iconUrl" class="image" />
              <div style="padding: 5px">
                <span>{{ template.templateName }}</span>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-card>
    </div>
    <div ref="deptChart" style="width: 500px; height: 250px" />
  </div>
</template>

<script>
  import { deptEcharts, getProcessDefinitions } from '@/api/dashboard'
  // import { mapGetters } from 'vuex'
  export default {
    name: 'Dashboard',
    // computed: {
    //   ...mapGetters([
    //     'nickName'
    //   ])
    // }
    data() {
      return {
        processCategories: [],
        deptOption: {
          title: {
            text: ''
          },
          tooltip: {},
          xAxis: {
            data: []
          },
          yAxis: {
            // 这里不需要设置data，y轴默认为数值轴
            // 可以根据需要添加其他配置项，例如：
            type: 'value',
            min: 0,
            max: 5, // 根据实际情况调整最大值
            interval: 1 // 设置间隔
          },
          series: [
            {
              name: '人数', // 鼠标悬浮显示的名称
              type: 'bar', // 这里使用柱状图类型，确保已经按需导入了BarChart组件
              data: []
            }
          ]
        }
      }
    },
    mounted() {
      this.initDeptChart()
      this.getProcessDefinitions()
    },
    methods: {
      /**
       * 获取部门流程类型和模板信息
       */
      async getProcessDefinitions() {
        this.processCategories = await getProcessDefinitions()
      },
      /**
       * 跳转到流程定义详情表单页面
       */
      gotoProcessDefinitionDetails(processDefinitionKey) {
        if (processDefinitionKey && processDefinitionKey === 'askForLeave') {
          this.$router.push({ path: '/process/definition', query: { processDefinitionKey: processDefinitionKey } })
        } else {
          this.$message.warning('暂未开发该模板的流程表单,请等待开发完成')
        }
      },
      async initDeptChart() {
        const result = await deptEcharts()
        const ecData = result.echartsData
        this.deptOption.title.text = result.title

        ecData.forEach(item => {
          this.deptOption.xAxis.data.push(item.deptName)
          this.deptOption.series[0].data.push(item.count)
        })
        // 基于准备好的dom，初始化echarts实例
        const deptChart = this.$echarts.init(this.$refs.deptChart)
        // 使用刚指定的配置项和数据显示图表。
        deptChart.setOption(this.deptOption)
      }
    }
  }
</script>

<style lang="scss" scoped>
  .dashboard {
    &-container {
      margin: 30px;
    }
    &-text {
      font-size: 30px;
      line-height: 46px;
    }
  }

  .time {
    font-size: 13px;
    color: #999;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: '';
  }

  .clearfix:after {
    clear: both;
  }
  .hoverable-card {
    transition: transform 0.3s, box-shadow 0.3s; /* 添加过渡效果 */
  }

  .hoverable-card:hover {
    transform: scale(1.05); /* 放大卡片 */
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2); /* 加深阴影 */
  }
</style>
